<?php
// +----------------------------------------------------------------------
// | Fanwe 多语商城建站系统 (Build on ThinkPHP)
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://www.fanwe.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 云淡风轻(97139915@qq.com)
// +----------------------------------------------------------------------


class SupplierGoodsAction extends CommonAction{
	public function publicGoods()
	{
		$id = intval($_REQUEST['id']);
		$vo = M("SupplierGoods")->getById($id);		
		$this->assign("vo",$vo);
	
		
		$gallery_list = D("GoodsGallery")->where("supplier_goods_id=".$id)->findAll();
		
		$this->assign("gallery_list",$gallery_list);
		$default_gallery = D("GoodsGallery")->where("supplier_goods_id=".$id)->find();
		$this->assign("default_gallery",$default_gallery);
		
		
		
		$lang_envs = D("LangConf")->findAll();
		$lang_ids = array();
		$dispname_arr = array();
		$lang_names = array();
		foreach($lang_envs as $lang_item)
		{
			$dispname_arr[] = "name_".$lang_item['id'];
			$lang_ids[]=$lang_item['id'];
			$lang_names[] = $lang_item['lang_name'];
		}
		$lang_ids = implode(",",$lang_ids);
		$this->assign("lang_ids",$lang_ids);
		$lang_names = implode(",",$lang_names);
		$this->assign("lang_names",$lang_names);

		$cate_list = D("GoodsCate")-> where("status=1")-> findAll();
		$cate_list = D("GoodsCate")-> toFormatTree($cate_list,$dispname_arr);	
		
		$brand_list = D("Brand")->findAll();
		
		$default_lang_id = D("LangConf")->where("lang_name='".C('DEFAULT_LANG')."'")->field("id")->find();
		$default_lang_id = $default_lang_id['id'];  //默认语言的ID
		$select_dispname = "name_".$default_lang_id;
		
		//输出重量单位
		$weight_list = D("Weight")->findAll();
		foreach($weight_list as $kk=>$vv)
		{
			$weight_list[$kk]['name'] = $vv['name_'.$default_lang_id];
		}
		$this->assign('weight_list',$weight_list);
		$type_list = D("GoodsType")->findAll();
		
		$suppliers_list = D("Suppliers")->findAll();
		$city_list = D("GroupCity")->where(array("status"=>1,"id"=>array("in",$_SESSION['admin_city_ids'])))->order("is_defalut desc,id asc")->findAll();
		
		$lang_envs = D("LangConf")->field("id")->findAll();
		$dispname_arr = array();
		foreach($lang_envs as $lang_item)
		{
			$dispname_arr[] = "name";
		}
		$city_list = D("GroupCity")-> toFormatTree($city_list,$dispname_arr);	
		
		$this->assign("type_list",$type_list);
		$this->assign("city_list",$city_list);
		$this->assign("suppliers_list",$suppliers_list);
		$this->assign("reviews_list",$reviews_list);
		$this->assign("select_dispname",$select_dispname);
		$this->assign("default_lang_id",$default_lang_id);
		$this->assign("cate_list",$cate_list);
		$this->assign("brand_list",$brand_list);
		$this->assign("goods_id",$id);

		$this->assign("session_id",$_SESSION['verify']);
		
		$this->display();
	}
	
	
	public function foreverdelete() {
		//删除指定记录
		$name=$this->getActionName();
		$model = D ($name);
		if (! empty ( $model )) {
			$pk = $model->getPk ();
			$id = $_REQUEST [$pk];
			if (isset ( $id )) {
				$condition = array ($pk => array ('in', explode ( ',', $id ) ) );
				if (false !== $model->where ( $condition )->delete ()) {
					//echo $model->getlastsql();
					$this->saveLog(1);
					$this->success (L('DEL_SUCCESS'));
				} else {
					$this->saveLog(0);
					$this->error (L('DEL_FAILED'));
				}
			} else {
				$this->saveLog(0);
				$this->error ( L('INVALID_OP'));
			}
		}
		$this->forward ();
	}
	
}
?>